package com.qiandao.xuexitong.handler;

import com.alibaba.excel.write.handler.RowWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.*;

public class AttendanceHeadStyleHandler implements RowWriteHandler {
    
    @Override
    public void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Integer relativeRowIndex, Boolean isHead) {
        if (isHead) {
            Workbook workbook = writeSheetHolder.getSheet().getWorkbook();
            
            // 创建标题样式
            CellStyle titleStyle = workbook.createCellStyle();
            titleStyle.setAlignment(HorizontalAlignment.CENTER);
            titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            Font titleFont = workbook.createFont();
            titleFont.setBold(true);
            titleFont.setFontHeightInPoints((short) 16);
            titleStyle.setFont(titleFont);
            
            // 创建信息样式
            CellStyle infoStyle = workbook.createCellStyle();
            infoStyle.setAlignment(HorizontalAlignment.CENTER);
            infoStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            Font infoFont = workbook.createFont();
            infoFont.setBold(true);
            infoFont.setFontHeightInPoints((short) 12);
            infoStyle.setFont(infoFont);
            
            // 设置样式
            if (relativeRowIndex == 0) {
                // 第一行（标题行）
                for (int i = 0; i < row.getLastCellNum(); i++) {
                    Cell cell = row.getCell(i);
                    if (cell != null) {
                        cell.setCellStyle(titleStyle);
                    }
                }
            } else {
                // 其他表头行
                for (int i = 0; i < row.getLastCellNum(); i++) {
                    Cell cell = row.getCell(i);
                    if (cell != null) {
                        cell.setCellStyle(infoStyle);
                    }
                }
            }
        }
    }
} 